package com.gz.logistics.library.listener;

import android.nfc.Tag;

import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;


public abstract class PostMoneyListener extends BaseListener {
    private String TAG = PostMoneyListener.class.getSimpleName();
    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_REF);
            String msg = response.getString(Constants.REQ_MSG);
            switch(status){
                case Constants.REQ_OK:
                    onResponseSuccess();
                    break;
                case Constants.REQ_PARTS_IS_EMPTY:
                    onNoNetWork();
                    break;
                case Constants.REQ_ERROR_USER_NAME:
                    onNoMoreData();
                    break;
                default:
                    onResponseFailed();
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }
    @Override
    public void onFailure(int statusCode,
                          Header[] headers,
                          Throwable throwable,
                          JSONObject errorResponse) {
        CrashHandler.e(throwable);
    }
    public abstract void onResponseSuccess();
}
